<template>
    <div v-if="visible" class="toast" :class="{ 'toast--success': type === 'success', 'toast--error': type === 'error' }">
      {{ message }}
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted, onUnmounted ,defineProps} from 'vue';
  
  const props = defineProps({
    message: String,
    type: {
      type: String,
      default: 'info'
    },
    duration: {
      type: Number,
      default: 3000
    }
  });
  
  const visible = ref(true);
  let timer;
  
  onMounted(() => {
    timer = setTimeout(() => {
      visible.value = false;
    }, props.duration);
  });
  
  onUnmounted(() => {
    clearTimeout(timer);
  });
  </script>
  
  <style scoped>
  .toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 9999;
  }
  
  .toast--success {
    background-color: #28a745;
  }
  
  .toast--error {
    background-color: #dc3545;
  }
  </style>